<template>
  <div class="jia">
    <section class="content">
      <div>
        <p>姓名</p>
        <input
          type="text"
          v-model="user"
          placeholder="必填，最多输入25个汉字"
        />
      </div>
      <div>
        <p>手机号</p>
        <input type="text" v-model="tel" placeholder="请输入手机号" />
      </div>
      <div>
        <p>地址信息</p>
        <input
          @click="show = !show"
          placeholder="请选择省/市/区/街道"
          v-model="ssqshow"
          class="inp"
        />
      </div>
      <div>
        <p>详细地址</p>
        <textarea
          type="text"
          placeholder="请输入详细地址，如道路、门牌号、校区、楼栋数、单元等"
          v-model="dizhi"
        ></textarea>
      </div>
    </section>
    <div class="morendizhi">
      <div>设为默认地址</div>
      <div class="switch">
        <van-switch
          v-model="checked"
          active-color="#ffffff"
          inactive-color="#2ec09a"
        />
      </div>
    </div>
    <div class="del" v-show="type==1">
      <div class="remove" @click="remove">删除地址</div>
    </div>
    <div class="footer" style="color: #fff">
      <div style="padding: 8px 16px">
        <van-button type="danger" block round @click="add"> 保存 </van-button>
      </div>
    </div>
    <van-popup v-model="show" position="bottom" :style="{ height: '40%' }">
      <!-- <van-picker
        show-toolbar
        :area-list="areaList"
      
        @confirm="onConfirm"
        @cancel="onCancel"
        @change="onChange"
      /> -->
      <van-area :area-list="areaList" 
        @confirm="onConfirm"
        @cancel="onCancel"
        @change="onChange"/>
    </van-popup>
  </div>
</template>

<script>
import {areaList} from '@vant/area-data'
import { log } from 'util';
export default {
  data() {
    return {
      show: false,
      ssqshow: "",
      checked: true,
      user: "",
      tel: "",
      dizhi: "",
     areaList,
     type:this.$route.query.type,
     editObj:this.$route.query.item
    };
  },
  mounted() {
    if(this.type == 1){
      this.user = this.editObj.user
      this.tel = this.editObj.tel
      this.ssqshow = this.editObj.ssqsshow
      this.dizhi = this.editObj.dizhi
    }
  },
  methods: {
    onConfirm(value) {
      console.log(value);
    console.log(value[0].name);
    this.ssqshow = value[0].name +value[1].name + value[2].name
      this.show = false;
    },
    onChange(picker, value, index) {
      //  this.$toast(`当前值：${value}, 当前索引：${index}`);
    },
    onCancel() {
      this.$toast("取消");
      this.show = false;
    },
    add() {
      let obj = {
        user: this.user,
        tel: this.tel,
        dizhi: this.dizhi,
        ssqsshow: this.ssqshow,
        id: new Date().getTime()
      };
      if (obj.ssqsshow && obj.dizhi && obj.user && obj.tel) {
        this.$router.push({ path: "/ClassAdddizhi" });
        this.$store.commit("adddizhi", obj);
      } else {
        this.$toast("请输入完整信息");
      }
    },
    remove() {
      if(this.type ){
        this.$store.commit("remove",this.editObj.id );
        this.$router.push('/classAdddizhi')
      }
    }
  },
  components: {}
};
</script>

<style lang='scss' scoped>
.jia {
  height: 667px;
  position: relative;
}
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
}
.content {
  padding: 0 15px;
  height: 425px;
  overflow: hidden;
  background-color: #fff;
  margin-bottom: 15px;
  div {
    padding: 15px 0;
    height: 98px;
    p {
      height: 30px;
      font-size: 14px;
      font-weight: normal;
      color: #595959;
    }
    input {
      width: 345px;
      height: 40px;
      background-color: #fdfdfd;
      border: 1px solid #ccc;
      padding-left: 10px;
      font-size: 14px;
      color: #333;
    }
    textarea {
      width: 100%;
      background: #fdfdfd;
      height: 64px;
      border: 0.26667vw solid #e8e8e8;
      color: #595959;
      padding: 2.66667vw;
      box-sizing: border-box;
      font-size: 16px;
    }
  }
}
.morendizhi {
  display: flex;
  padding: 0 20px;
  height: 48px;
  background-color: #fff;
  line-height: 48px;
  font-size: 16px;
  div {
    flex-basis: 50%;
  }
  .switch .van-switch {
    float: right;
    margin-top: 10px;
  }
}
.del {
  margin-top: 10px;
  display: flex;
  padding: 0 20px;
  height: 48px;
  background-color: #fff;
  line-height: 48px;
  font-size: 16px;
  .remove {
    float: right;
  }
}
</style>
